import { observable, action } from 'mobx'
import IUser from '../interfaces/IUser';

class UserStore {
  /**
   * 用户信息
   */
  @observable user: IUser | null = null;

  /**
   * 设置用户信息
   * @param user
   */
  @action
  setUserInfo(user?: IUser) {
    this.user = user || null;
    if (user) {
      window.localStorage.setItem('user', JSON.stringify(user));
    } else {
      window.localStorage.removeItem('user');
    }
  }
}

export default new UserStore;
